﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ManagedCIMG;
namespace SampleTester
{
    public partial class Form1 : Form
    {
        string imagefilename;
        ManagedCImg c;
        Bitmap bm;
        ManagedCImg temp;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dl = new OpenFileDialog();
            if (dl.ShowDialog()==DialogResult.OK)
            {
                Bitmap bm = new Bitmap(dl.FileName);
                imagefilename=dl.FileName;
                pictureBox1.Image = bm;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bm=new Bitmap (imagefilename);
            c = new ManagedCImg(bm);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //Bitmap tempimage = c.ToBitmap();
            //pictureBox1.Image = c.ToBitmap();
            c.Display();
        }

        private void togrey(object sender, EventArgs e)
        {
            c.ToGray(100, true, false);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            temp = new ManagedCImg();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = c.getCImgVersion().ToString();
        }
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            temp.BitmapImage = bm;   //assign image as a new then apply the threshold again.
            label3.Text = trackBar1.Value.ToString();
            temp.ToGray((float)trackBar1.Value, true, false);
            pictureBox1.Image = temp.ToBitmap();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            c.Blur(10f, true, true);
            pictureBox1.Image = c.ToBitmap();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //ManagedCImg im2 = new ManagedCImg();
            //im2.BitmapImage = (Bitmap)pictureBox1.Image;
            //im2.ToGray(30, false, false);
            //pictureBox1.Image = im2.ToBitmap();
            unsafe // TODO: icant still figure out a way to convert string to char* 
            {
                int num = 55;
                int* f = &num;
                c.DrawText(100, 100, "dfdf", f);
            } 
        }
    }
}
